home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
cgazv5n5.arc
/
XMSEMB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-23
|
3KB
|
75 lines
/*--- XMSEMB.C --------------------------- Listing 5 ------
* XMS UMB Functions. Prints greeting from extended memory.
* by David Babcock
*
* Must be linked with XMSGEN (Listing 1)
*
* Validated for Microsoft and Borland C/C++
*
* (c) 1991 C Gazette. Object Code may be used freely,
* source code may be used if authorship and publication
* are acknowledged.
*-------------------------------------------------------*/
#include <stdio.h>
#include <dos.h>
#include <string.h>
#include "xms.h"
static char hello[] = "hello from extended memory" ;
static char hello_again [ 30 ] ;
void main ( void )
{
unsigned int ver ;
unsigned int largestBlock ;
int allocResult ;
unsigned int handle ;
ver = ( unsigned int ) GetXMSVersionNumber ( ) ;
printf ( "XMS version %s\n",
PrintXMSVersionNumber ( ver ) ) ;
if ( ver >= 0x200 )
{
largestBlock = QueryFreeExtendedMemory() & 0xFFFF ;
printf ( "Largest free extended memory block:\n%uK\n",
largestBlock ) ;
if ( largestBlock > 0 )
{
allocResult =
( AllocateExtendedMemoryBlock(largestBlock) == 0 );
handle = xms_struc.ret_dx ;
if ( allocResult )
{
/* copy from conventional memory to the EMB */
XMSMoveStruct.Length =
(( strlen ( hello ) + 1 ) + 1 )
& ~1L ; /* round up */
XMSMoveStruct.SourceHandle = 0 ;
XMSMoveStruct.SourceOffset.p =
( void far * ) hello ;
XMSMoveStruct.DestHandle = handle ;
XMSMoveStruct.DestOffset.o = 0 ;
MoveExtendedMemoryBlock
(( void far * ) &XMSMoveStruct ) ;
/* now copy from EMB to conventional memory */
XMSMoveStruct.Length =
(( strlen ( hello ) + 1 ) + 1 )
& ~1L ; /* round up */
XMSMoveStruct.SourceHandle = handle ;
XMSMoveStruct.SourceOffset.o = 0 ;
XMSMoveStruct.DestHandle = 0 ;
XMSMoveStruct.DestOffset.p =
( void far * ) hello_again ;
MoveExtendedMemoryBlock
(( void far * ) &XMSMoveStruct ) ;
printf ( "%s\n", hello_again ) ;
FreeExtendedMemoryBlock ( handle ) ;
}
}
}
}